import java.util.*;

public class JIdeaPool {

	Map<JTopic, Set<JIdea>> pool;
	
	public JIdeaPool(){
		
		pool= new HashMap<JTopic, Set<JIdea>>();
	}
	
	public void add(JTopic topic){
		if(topic==null){
			throw new NullPointerException();
			}
		if(pool.containsKey(topic)==false){
			pool.put(topic, new HashSet<JIdea>());
		}
	}
	
	 public void add(JIdea idea, JTopic topic) {
		 if(topic==null || idea==null) 
				throw new NullPointerException();
         if (pool.containsKey(topic)==false) {
                 Set<JIdea> Ideas = new HashSet<JIdea>();
                 Ideas.add(idea);
                 pool.put(topic, Ideas);
         } else {
                 pool.get(topic).add(idea);
         }
 }
	
	public boolean remove(JTopic topic){
		if(topic==null)
			throw new NullPointerException();
		if(pool.containsKey(topic)==true){
			pool.put(topic, new HashSet<JIdea>());
			pool.remove(topic);
			return true;
		}
		else{
			return false;
		}
	}
	
	public boolean remove(JIdea idea){
		if(idea==null) 
			throw new NullPointerException();
		if(pool.containsValue(idea)==true){
			HashSet<JTopic> topics = (HashSet<JTopic>) pool.keySet();
			for(JTopic topic : topics){
				Set<JIdea> ideas = pool.get(topic);
				ideas.remove(idea);
				pool.put(topic, ideas);
			}
		return true;
		}
		return false;
	}
	
	public int numberOfTopics(){
		return pool.size();
	}
	
	public int numberOfIdeas(){
		int temp = 0;
		Set<JTopic> topics = pool.keySet();
		for(JTopic topic : topics){
			Set<JIdea> ideas = pool.get(topic);
			temp = temp+ideas.size();
		}
		return temp;
	}
	
}
